#ifndef _API_BTSTACK_H
#define _API_BTSTACK_H

//蓝牙功能
#define PROF_A2DP                       0x0007  //蓝牙音乐功能
#define PROF_HID                        0x0018  //蓝牙键盘功能
#define PROF_HFP                        0x0060  //蓝牙通话功能
#define PROF_SPP                        0x0080  //蓝牙串口功能
#define PROF_PBAP                       0x0100  //蓝牙电话本功能
#define PROF_HSP                        0x0200
#define PROF_MAP                        0x0400  //蓝牙短息功能

//蓝牙特性
#define HFP_BAT_REPORT                  0x01    //是否支持手机电量显示
#define HFP_3WAY_CALL                   0x02    //是否支持三通电话
#define HFP_IOS_RING                    0x04    //是否支持IOS来电铃声
#define HFP_CALL_PRIVATE                0x08    //是否打开强制私密接听
#define HFP_SIRI_CMD                    0x10    //是否打开siri控制命令
#define HFP_EC_AND_NR                   0x20    //是否打开手机端回音和降噪
#define A2DP_VOL_CTRL                   0x01    //是否支持手机音量控制
#define A2DP_RECON_CTRL                 0x02    //是否打开A2DP控制键回连
#define A2DP_IOS_FLAG                   0x04    //是否iso系统
#define A2DP_AVCTP_FLAG                 0x08    //是否支持AVCTP控制功能
#define A2DP_AVDTP_DELAY_REPORT         0x10    //是否支持AVDTP delay report功能

//AVRCP消息
#define AVC_VOLUME_UP               0x41
#define AVC_VOLUME_DOWN             0x42
#define AVC_MUTE                    0x43
#define AVC_PLAY                    0x44
#define AVC_STOP                    0x45
#define AVC_PAUSE                   0x46
#define AVC_RECORD                  0x47
#define AVC_REWIND                  0x48
#define AVC_FAST_FORWARD            0x49
#define AVC_EJECT                   0x4a
#define AVC_FORWARD                 0x4b
#define AVC_BACKWARD                0x4c

//扩展标志
#define BT_FLAG0_TWS_SCAN           0x01
#define BT_FLAG0_CLK_ADVANCE        0x02
#define BT_FLAG0_TWS_M_RECON        0x04
#define BT_FLAG0_TWS_FAST_RECON     0x08
#define BT_FLAG0_TWS_MENU_PAIR      0x10    //手动控制TWS连接, 调用tws api
#define BT_FLAG0_BAT_HOUSE          0x20

#define BT_FLAG1_LTX_RECON          0x01

typedef struct
{
    u8 txpwr;                       //0=4dbm, 1=3dbm, 2=2dbm, 3=1dbm, 4=0dbm
    u8 packet;                      //0=LQFP48, 1=QFN32, 3=, 4=, 5=TSSOP24, 6=SOP16
    u8 res[6];
} rf_cfg_t;

typedef struct {
    u8 pwrup_connect_times;
    u8 tout_connect_times;
    u16 profile;
    u8 max_acl_link;
    u8 max_nor_link;
    u8 a2dp_feature;
    u8 hfp_feature;
    u8 vx_set;
    u16 scan_timeout;
    u8 res[2];

    u16 dual_mode           : 1;
    u16 tws_mode            : 1;
    u16 fcc_test_mode       : 1;
    u16 cbt_test_mode       : 1;
    u16 simple_pair_mode    : 1;
    u16 scan_ctrl           : 1;

    u16 sco_plc_en          : 1;
    u16 sco_msbc_en         : 1;
} bt_cfg_t;

//蓝牙状态
enum {
    BT_STA_OFF,                                 //蓝牙模块已关闭
    BT_STA_INITING,                             //初始化中
    BT_STA_IDLE,                                //蓝牙模块打开，未连接

    BT_STA_SCANNING,                            //扫描中
    BT_STA_DISCONNECTING,                       //断开中
    BT_STA_CONNECTING,                          //连接中

    BT_STA_CONNECTED,                           //已连接
    BT_STA_PLAYING,                             //播放
    BT_STA_INCOMING,                            //来电响铃
    BT_STA_OUTGOING,                            //正在呼出
    BT_STA_INCALL,                              //通话中
    BT_STA_OTA,                                 //OTA升级中
};

//通话状态
enum {
    BT_CALL_IDLE,                               //
    BT_CALL_INCOMING,                           //来电响铃
    BT_CALL_OUTGOING,                           //正在呼出
    BT_CALL_ACTIVE,                             //通话中
    BT_CALL_3WAY_CALL,                          //三通电话或两部手机通话
};

//蓝牙通知
enum {
    BT_NOTICE_INIT_FINISH,                      //蓝牙初始化完成
    BT_NOTICE_DISCONNECT,                       //蓝牙断开
    BT_NOTICE_LOSTCONNECT,                      //蓝牙连接丢失
    BT_NOTICE_CONNECTED,                        //蓝牙连接成功
    BT_NOTICE_INCOMING,                         //来电
    BT_NOTICE_RING,                             //来电响铃
    BT_NOTICE_OUTGOING,                         //去电
    BT_NOTICE_CALL,                             //建立通话
    BT_NOTICE_SET_SPK_GAIN,                     //设置通话音量
    BT_NOTICE_MUSIC_PLAY,                       //蓝牙音乐开始播放
    BT_NOTICE_MUSIC_STOP,                       //蓝牙音乐停止播放
    BT_NOTICE_MUSIC_CHANGE_VOL,                 //改变蓝牙音乐音量
    BT_NOTICE_MUSIC_SET_VOL,                    //设置蓝牙音乐音量
    BT_NOTICE_HID_CONN_EVT,                     //HID服务连接事件
    BT_NOTICE_KEY_PRESS_EVT,                    //远端按键按下
    BT_NOTICE_TBOX_EVT,
    BT_NOTICE_TWS_SET_VOL,                      //设置TWS音乐音量
    BT_NOTICE_TWS_HID_SHUTTER,                  //远端TWS拍照键
    BT_NOTICE_TWS_INFO,                         //TWS同步信息
    BT_NOTICE_TWS_USER_KEY,                     //TWS自定义按键
    BT_NOTICE_TWS_SEARCH_STATUS,
    BT_NOTICE_TWS_TO_STATUS,
    BT_NOTICE_TWS_RES_PLAY,
    BT_NOTICE_TWS_RES3,
    BT_NOTICE_TWS_RES4,
    BT_NOTICE_TWS_RES5,
    BT_NOTICE_TWS_RES6,
    BT_NOTICE_TWS_RES7,
    BT_NOTICE_SCO_SETUP,
    BT_NOTICE_SCO_KILL,
    BT_NOTICE_CONNECT_STATUS,
    BT_NOTICE_DISCONNECT_STATUS,
    BT_NOTICE_BT_INFO,
    BT_NOTICE_INQUIRY_FINISH,
    BT_NOTICE_PULLPHONEBOOK_FINISH,             //获取电话薄完成
    BT_NOTICE_HFP_INDICATOR_STATUS,
    BT_NOTICE_SREVICE_CLASS,
    BT_NOTICE_SSP_NUMERIC_VALUE,
    BT_NOTICE_RECON_FINISH,                    //增加个bt_nor_connect连接手机失败notice 状态
    BT_NOTICE_NETWORK_CALL,                     //网络通话
    BT_NOTICE_PHONE_CALL,                       //手机通话
    BT_NOTICE_PROFILE,
};

//控制消息
enum bt_msg_t {
    BT_MSG_OFF          = 0,                    //关闭蓝牙
    BT_MSG_ON,                                  //打开蓝牙
    BT_MSG_SCAN_ENABLE,                         //打开扫描
    BT_MSG_SCAN_DISABLE,                        //关闭扫描
    BT_MSG_CONNECT,                             //连接蓝牙
    BT_MSG_DISCONNECT,                          //断开蓝牙
    BT_MSG_PLAY_PAUSE,                          //切换播放、暂停
    BT_MSG_VOL_CHANGE,                          //音量调整
    BT_MSG_CALL_REDIAL,                         //回拨电话（最后一次通话）
    BT_MSG_CALL_ANSWER_INCOM,                   //接听来电
    BT_MSG_CALL_TERMINATE,                      //挂断通话或来电
    BT_MSG_CALL_SWAP,                           //切换三通电话
    BT_MSG_HFP_REPORT_BAT,                      //报告电池电量
    BT_MSG_HFP_SPK_GAIN,                        //设置通话扬声器音量
    BT_MSG_HFP_MIC_GAIN,                        //设置通话麦克风音量
    BT_MSG_HFP_PRIVATE_SWITCH,                  //切换私密通话
    BT_MSG_HID_CONNECT,                         //连接HID
    BT_MSG_HID_DISCONNECT,                      //断开HID
    BT_MSG_AUDIO_BYPASS,                        //忽略蓝牙SBC/SCO AUDIO
    BT_MSG_AUDIO_ENABLE,                        //使能蓝牙SBC/SCO AUDIO
    BT_MSG_TWS_SCAN_ENABLE,                     //打开TWS扫描，连接后会自动关闭
    BT_MSG_TWS_SCAN_DISABLE,                    //关闭TWS扫描
    BT_MSG_TWS_DISCONNECT,                      //断开TWS连接
    BT_MSG_TWS_CONNECT,                         //建立TWS连接
    BT_MSG_TWS_SEARCH_SLAVE,                    //搜索并建立TWS连接
    BT_MSG_TWS_NOTICE_RING,
    BT_MSG_SWITCH_SIRI,
    BT_MSG_OTA_READ,
    BT_MSG_OTA_STATUS,
    BT_MSG_CALL_REDIAL_NUMBER,                  //回拨电话（从hfp_get_outgoing_number获取号码）
    BT_MSG_HFP_AT_CMD,
    BT_MSG_HID_SEND,
    BT_MSG_CALL_ANSWER_INCOM_REJ_OTHER,         //接听来电，三通时挂断当前通话
    BT_MSG_SPP_SEND,
    BT_MSG_CONNECT_ADDRESS,
    BT_MSG_HFP_CONNECT_AND_DISCONNECT,
    BT_MSG_TWS_SYNC_INFO,
    BT_MSG_NOR_CONNECT,
    BT_MSG_NOR_DISCONNECT,
    BT_MSG_BLE_SEND,
    BT_MSG_BLE_UPDATE_CONN_PARAM,
    BT_MSG_RESET_BT_NAME,
    BT_MSG_SWITCH_PALY,
    BT_MSG_A2DP_CONNECT_AND_DISCONNECT,
    BT_MSG_FCC_TEST_FUNC,
    BT_MSG_GET_REMOTE_PHONE_NUMBER,
    BT_MSG_INQUIRY_START,
    BT_MSG_MAX,

    BT_MSG_HID_KEY      = 0x30,                 //HID按键
    BT_MSG_HID_CONSUMER,                        //CONSUMER按键
    BT_MSG_TWS_USER_KEY,                        //TWS用户自定义消息
    BT_MSG_HID_TOUCH_SCREEN,                    //触摸屏
    BT_MSG_PBAP,
    BT_MSG_NULL,
    BT_MSG_HSP_SEND,
    BT_MSG_SYNC_INFO,                           //主副耳同步一些状态消息
    BT_MSG_TBOX,
    BT_MSG_MAP,
    BT_MSG_PBAP_PULL_CONTINUE_TIME,
    BT_MSG_NUMERIC_COMPARISON_RES,
    BT_MSG_SET_SCAN,
    BT_MSG_REMOTE_CONTROL,
    BT_MSG_HID_MOUSE,                           //HID 鼠标
    BT_MSG_PARAM_MAX,

    BT_MSG_VOLUME_UP    = AVC_VOLUME_UP,
    BT_MSG_VOLUME_DOWN  = AVC_VOLUME_DOWN,
    BT_MSG_PLAY         = AVC_PLAY,             //播放
    BT_MSG_PAUSE        = AVC_PAUSE,            //暂停
    BT_MSG_STOP         = AVC_STOP,             //停止
    BT_MSG_PREV         = AVC_BACKWARD,         //上一曲
    BT_MSG_NEXT         = AVC_FORWARD,          //下一曲
    BT_MSG_REWIND       = AVC_REWIND,           //开始快退
    BT_MSG_FAST_FORWARD = AVC_FAST_FORWARD,     //开始快进
    BT_MSG_REWIND_END       = AVC_REWIND|0x80,  //结束快退
    BT_MSG_FAST_FORWARD_END = AVC_FAST_FORWARD|0x80, //结束快进

    BT_MSG_EXT          = 0xff,                    //扩展一下蓝牙消息
    BT_MSG_GET_PLAY_STATUS_INFO = (0x01<<8) | BT_MSG_EXT,
    BT_MSG_GET_ID3_TAG          = (0x02<<8) | BT_MSG_EXT,    //主动发起获取ID3信息
    BT_MSG_SEARCH_UUID_LIST     = (0x03<<8) | BT_MSG_EXT,
    BT_MSG_SPP_CON_AND_DISCON   = (0x04<<8) | BT_MSG_EXT,
    BT_MSG_BLE_TINY_SCAN_START  = (0x05<<8) | BT_MSG_EXT,
    BT_MSG_BLE_TINY_SCAN_STOP   = (0x06<<8) | BT_MSG_EXT,
};

extern bt_cfg_t bt_cfg;

//control
void bt_fcc_init(void);
void bt_init(void);                             //初始化蓝牙变量
int bt_setup(void);                             //打开蓝牙模块
void bt_off(void);                              //关闭蓝牙模块
void bt_wakeup(void);                           //唤醒蓝牙模块
void bt_send_msg(uint msg);                     //蓝牙控制消息，参数详见bt_msg_t
void bt_audio_bypass(void);                     //蓝牙SBC/SCO通路关闭
void bt_audio_enable(void);                     //蓝牙SBC/SCO通路使能
u8 bt_get_packet(u8 index);
uint8_t bt_get_hvbko(u8 rf_packet);
void bt_set_sco_far_delay(void *buf, uint size, uint delay);

void bt_set_scan(bool enable);                  //打开/关闭发现与连接状态
void bt_set_scan_fix(u8 scan);
void bt_connect(void);                          //蓝牙设备回连
void bt_disconnect(void);                       //蓝牙设备断开
void bt_hid_connect(void);                      //蓝牙HID服务回连
void bt_hid_disconnect(void);                   //蓝牙HID服务断开
int bt_hid_is_connected(void);
bool bt_hid_is_ready_to_discon(void);
void bt_ssp_numeric_comparison_res(u8 result);
#if BT_HID_MOBILE_REMOTE_CONTROL
typedef enum {
    //mouse control: report ID: 0x01
    RC_MOUSE_INIT_POSITION,
    RC_MOUSE_SWIPE_DOWN,
    RC_MOUSE_SWIPE_UP,
    RC_MOUSE_SWIPE_RIGHT,
    RC_MOUSE_SWIPE_LEFT,
    RC_MOUSE_SCROLL_UP,
    RC_MOUSE_SCROLL_DOWN,
    RC_MOUSE_PAUSE_PLAY,
    RC_MOUSE_UPVOTE,
    RC_MOUSE_CLICK,
    RC_MOUSE_POINTER_UP,
    RC_MOUSE_POINTER_DOWN,
    RC_MOUSE_POINTER_RIGHT,
    RC_MOUSE_POINTER_LEFT,
    //application control: report ID: 0x02
    RC_AC_VOL_INCREASE,
    RC_AC_VOL_DECREASE,
    RC_AC_POWER_OFF,
    RC_AC_MAIN_MENU,
    //TODO: RC_CUSTOM_DATA,
    REMOTE_CONTROL_NUM,
}remote_control_e;
void btstack_hid_mobile_remote_control(remote_control_e key);//在main线程或者更低优先级线程调用
#endif

//status
uint bt_get_disp_status(void);                  //获取蓝牙的当前显示状态, V060
uint bt_get_status(void);                       //获取蓝牙的当前状态
uint bt_get_call_indicate(void);                //获取通话的当前状态
uint bt_get_siri_status(void);                  //获取SIRI当前状态, 0=SIRI已退出, 1=SIRI已唤出
bool bt_is_calling(void);                       //判断是否正在通话
bool bt_is_playing(void);                       //判断是否正在播放
bool bt_is_ring(void);                          //判断是否正在响铃
bool bt_is_testmode(void);                      //判断当前蓝牙是否处于测试模式
bool bt_is_sleep(void);                         //判断蓝牙是否进入休眠状态
bool bt_is_connected(void);                     //判断蓝牙是否已连接（TWS副耳被连接，或主耳与手机已连接）
bool bt_is_ios_device(void);                    //判断当前播放的是否ios设备
uint32_t bt_sleep_proc(void);
void bt_enter_sleep(void);
void bt_exit_sleep(void);
void updata_bt_name(char *bt_name);
bool bt_backstage_play_check(uint status, u32 check_time_ms);
u8 bt_get_sco_setup_status(void);
bool bt_play_data_check(u32 check_time_ms);
bool bt_a2dp_is_connected(void);
bool bt_spp_is_connected(void);                 //判断SPP是否已经连接
bool bt_hfp_is_connected(void);
void bt_spp_reset_buf(void);
u16 bt_spp_get_mtu(void);
uint8_t get_bt_link_num(void);                  //当前连接设备数目

//info
bool bt_get_link_btname(uint8_t index, char *name, uint8_t max_size); //index: 0=link0, 1=link1, 0xff=auto(default link0)

//tws api
bool bt_tws_is_connected(void);                 //tws设备是否已连接
bool bt_tws_is_slave(void);                     //tws主从判断，注意要先判断tws是否已连接
bool bt_tws_is_scaning(void);                   //tws是否已打开可被搜索与连接
void bt_set_tws_scan(bool enable);              //打开/关闭tws可被搜索与连接
void bt_tws_disconnect(void);                   //断开tws设备
void bt_tws_connect(void);                      //回连tws设备
void bt_tws_search_slave(void);                 //搜索tws设备，并建立连接
uint bt_tws_get_link_info(uint8_t *bd_addr);    //获取tws配对信息，返回值（0=未连接过TWS，0x80=作为master连过副耳，0x81=作为slave连接过主耳），被连地址放在bd_addr
void bt_tws_delete_link_info(void);             //删除tws配对信息
bool bt_tws_user_key(uint keycode);             //发送tws自定义按键, 10bit有效
void bt_tws_status_sync(uint8_t status, u32 *ticks); //等待tws状态同步
bool bt_tws_ring_number_sync(u32 ticks);        //查询tws报号是否已同步
void bt_tws_switch(void);                       //主从切换，例如通话时切主副MIC
bool bt_nor_is_connected(void);                 //是否已连接手机
void bt_nor_connect(void);                      //回连手机
void bt_nor_disconnect(void);                   //断开手机
bool bt_nor_get_link_info(uint8_t *bd_addr);    //获取手机配对信息，bd_addr=NULL时仅查询是否存在回连信息
bool bt_nor_get_link_info_addr(uint8_t *bd_addr, uint8_t order);    //获取第n个手机配对信息，bd_addr=NULL时仅查询是否存在回连信息
void bt_nor_delete_link_info(void);             //删除手机配对信息
s16 bt_nor_get_connected_rssi(void);             //获取蓝牙连接后的rssi值,可简单用于样机到手机的距离判断
u8 bt_tws_get_force_role(void);
u32 bt_tws_get_ticks(void);

enum {
    TWS_RES_NUM_0,
    TWS_RES_NUM_1,
    TWS_RES_NUM_2,
    TWS_RES_NUM_3,
    TWS_RES_NUM_4,
    TWS_RES_NUM_5,
    TWS_RES_NUM_6,
    TWS_RES_NUM_7,
    TWS_RES_NUM_8,
    TWS_RES_NUM_9,
    TWS_RES_LANGUAGE_ZH,
    TWS_RES_LANGUAGE_EN,
    TWS_RES_LOW_BATTERY,
    TWS_RES_CONNECTED,
    TWS_RES_DISCONNECT,
    TWS_RES_PAIRING,
    TWS_RES_CALL_HANGUP,
    TWS_RES_CALL_REJECT,
    TWS_RES_REDIALING,
    TWS_RES_MAX,
};

void tws_res_init(void);                        //api
void tws_res_play(uint8_t index);               //api

void tws_mp3_res_play_kick(u32 addr, u32 len);  //tws_res开始播放
u32 tws_res_sync(u32 limit);                    //tws_res同步
void tws_res_add(u8 index, u32 ticks);          //tws_res加入列表
void tws_res_proc(void);                        //tws_res流程处理


//蓝牙连接
#define bt_scan_enable()                        bt_send_msg(BT_MSG_SCAN_ENABLE)     //打开扫描
#define bt_scan_disable()                       bt_send_msg(BT_MSG_SCAN_DISABLE)    //关闭扫描

#define bt_fcc_test_start()                     bt_send_msg(BT_MSG_FCC_TEST_FUNC)
#define bt_inquiry_start()                      bt_send_msg(BT_MSG_INQUIRY_START)   //蓝牙开始搜索
#define bt_a2dp_connect_and_disconnect()        bt_send_msg(BT_MSG_A2DP_CONNECT_AND_DISCONNECT)   //断开 或者连接A2DP 链路
#define bt_hfp_connect_and_disconnect()         bt_send_msg(BT_MSG_HFP_CONNECT_AND_DISCONNECT)
#define bt_search_uuid_list()                   bt_send_msg(BT_MSG_SEARCH_UUID_LIST)
#define bt_spp_connect_and_disconnect()         bt_send_msg(BT_MSG_SPP_CON_AND_DISCON)

//蓝牙音乐
#define bt_music_play()                         bt_send_msg(BT_MSG_PLAY)            //播放
#define bt_music_pause()                        bt_send_msg(BT_MSG_PAUSE)           //暂停
#define bt_music_play_pause()                   bt_send_msg(BT_MSG_PLAY_PAUSE)      //切换播放/暂停
#define bt_music_stop()                         bt_send_msg(BT_MSG_STOP)            //停止
#define bt_music_prev()                         bt_send_msg(BT_MSG_PREV)            //上一曲
#define bt_music_next()                         bt_send_msg(BT_MSG_NEXT)            //下一曲
#define bt_music_rewind()                       bt_send_msg(BT_MSG_REWIND)          //开始快退
#define bt_music_rewind_end()                   bt_send_msg(BT_MSG_REWIND_END)      //结束快退
#define bt_music_fast_forward()                 bt_send_msg(BT_MSG_FAST_FORWARD)    //开始快进
#define bt_music_fast_forward_end()             bt_send_msg(BT_MSG_FAST_FORWARD_END)//结束快进
#define bt_music_play_private_switch()          bt_send_msg(BT_MSG_A2DP_CONNECT_AND_DISCONNECT)  //断开 或者连接A2DP 链路
#define bt_2acl_switch_music_play()             bt_send_msg(BT_MSG_SWITCH_PALY);

#define bt_music_paly_status_info()             bt_send_msg(BT_MSG_GET_PLAY_STATUS_INFO | BT_MSG_EXT)
#define bt_music_get_id3_tag()                  bt_send_msg(BT_MSG_GET_ID3_TAG | BT_MSG_EXT)

//蓝牙通话
#define bt_call_redial_last_number()            bt_send_msg(BT_MSG_CALL_REDIAL)     //电话回拨（最后一次通话）
#define bt_call_answer_incoming()               bt_send_msg(BT_MSG_CALL_ANSWER_INCOM) //接听电话，三通时挂起当前通话
#define bt_call_answer_incom_rej_other()        bt_send_msg(BT_MSG_CALL_ANSWER_INCOM_REJ_OTHER)	//接听电话，三通时挂断当前通话
#define bt_call_terminate()                     bt_send_msg(BT_MSG_CALL_TERMINATE)  //挂断电话
#define bt_call_swap()                          bt_send_msg(BT_MSG_CALL_SWAP)       //切换三通电话
#define bt_call_private_switch()                bt_send_msg(BT_MSG_HFP_PRIVATE_SWITCH)       //切换三通电话
#define bt_siri_switch()                        bt_send_msg(BT_MSG_SWITCH_SIRI)     //开关SIRI, android需要在语音助手中打开“蓝牙耳机按键启动”, ios需要打开siri功能
#define bt_call_get_remote_phone_number()       bt_send_msg(BT_MSG_GET_REMOTE_PHONE_NUMBER)

uint bt_get_hfp_feature(void);

//bt_spp_tx 蓝牙SPP发送,默认最大一包能发240byte.
//返回值如下：
//0: 发送成功，返回其它值表示发送失败
//1：发送失败,主要是参数检查(packet == NULL || len == 0 || (len > 240) 会返回该值
//2: 发送失败,表明蓝牙上一包数据还未发送完，需要重新发送该包数据
int bt_spp_tx(uint8_t *packet, uint16_t len);
void bt_sdp_search_init_do(u8 *handle_list, u8 *pattern, u32 *record_handle, u8 *service_class, uint16_t max_record_count);

//hid
bool bt_hid_key(int keycode);                 //标准HID键, 如Enter
bool bt_hid_consumer(int keycode);            //自定义HID键, 如VOL+ VOL-
bool bt_hid_send(void *buf, uint len, bool auto_release);

struct ts_ctl_t {
    uint8_t act;
    uint8_t res;
    uint16_t x;
    uint16_t y;
};
bool bt_hid_touch_screen(int keycode);
bool bt_hid_touch_screen_set_key(void *ts);

//HID mouse simulator
typedef struct __attribute__((packed)) {
    uint8_t left_click : 1;
    uint8_t right_click : 1;
    uint8_t middle_click : 1;
    uint8_t reserved : 5;
    int16_t x_diff;
    int16_t y_diff;
}hid_mouse_action_t;

bool bt_hid_mouse_action_send(void *action);

bool bt_pb_check(void);
//pbap
void bt_pbap_start(u8 type);                    //type：获取本地号码:BIT(0)、获取来电号码:BIT(1)、获取去电号码:BIT(2)、获取未接号码:BIT(3); 获取SIM卡使能：BIT(4)
void bt_pbap_abort(void);                       //终止电话本的获取
u32 bt_pbap_get_sta(void);                      //获取电话本状态，0：IDLE； 1：获取中
void bt_pbap_set_continue_time(u8 time);        //或取电话本每包数据之间的延迟时间，时间：time*50MS，与bt_pbap_start函数一起使用
uint16_t bt_pbap_set_phonebook_count();         //设置电话本获取的数量
uint16_t bt_pbap_set_phonebook_offset();       //设置电话本获取时的偏移量
//map
void bt_map_start(void);                     	//MAP的获取
void bt_map_abort(void);                        //终止MAP的获取
//hsp
void bt_hsp_call_switch(void);                  //挂断/接听
void bt_hsp_sco_conn(void);                     //建立HSP SCO连接
void bt_hsp_sco_disconn(void);                  //断开HSP SCO连接
void lc_sco_set_hci_rx(u16 *ptr, u32 samples);  //通话上传给手机数据接口,常用于对接IIS DSP降噪MIC
//a2dp
bool a2dp_get_playing_device_address(uint8_t *bd_addr);
/*****************************************************************************
 * BLE API函数接口
 *****************************************************************************/
u8 le_get_status(void);
bool le_is_connect(void);
void le_set_adv(u8 chanel, u8 type);
void le_set_adv_interval(u16 interval);
void le_enable_adv(u8 allow);
void le_disable_adv(void);
void le_disconnect(void);
bool le_tx_notify(u8 index, u8* buf, u8 len);
void le_update_conn_param(u16 interval_min, u16 interval_max, u16 latency, u16 timeout);
bool le_set_adv_data(const u8 *adv_buf, u32 size);
void le_bat_house_ctrl(uint opcode);            //0=close, 1=open/update_disp
u16 le_get_gatt_mtu(void);
void le_sm_init(uint8_t security_req_en, uint8_t io_capability, uint8_t authentication_req_flag);
void clear_att_attributes_tx(void);
u16 le_get_write_max_len(void);
void ble_user_white_list_set(uint8_t *bd_addr, uint8_t enable);     ///设置连接的白名单地址，写1使能，写0不使能
void ble_user_conn_addr_get(uint8_t *bd_addr);                      ///获取当前连接的BLE地址，可以通过此处获取，再设置进去white list
void updata_scan_rsp_data(void);    ///更新scan_rsp数据，可以用于修改蓝牙名字后的更新

extern bool house_state;
bool ble_bat_house_get_role(void);
void ble_bat_house_set_state(bool state);       //state: 1=house_open_adv, 0=house_close_adv and then disable_adv
void ble_bat_house_update_state(uint step);     //step: 2=house_open_adv, 1=house_close_adv, 0=disable_adv

//BLE 扫描功能API
void ble_tiny_set_scan_param(uint16_t interval, uint16_t window); //设置扫描间隔跟扫描窗口单位0.625MS
void ble_adv_scan_start(void);
void ble_adv_scan_stop(void);
uint8_t ble_tiny_scan_status(void);

#endif //_API_BTSTACK_H
